import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		token: '',
		user: null,
		config: {}
	},
	getters: {
		getToken: function(state) {
			return state.token || uni.getStorageSync('token') || ''
			// return state.token || ''
		},
		tabbar: function(state) {
			return ['/pages/index/index', '/pages/category/list', '/pages/cabinet/list', '/pages/center/index']
		},
		userInfo: function(state) {
			
			return state.user || uni.getStorageSync('user') || {}
			
		},
		config: function(state) {
			
			return state.config || uni.getStorageSync('config') || {}
		},

	},
	mutations: {
		setToken: (state, data) => {
			
			uni.setStorageSync('token', data)
			state.token = data
		},
		setConfig: (state, data) => {
			uni.setStorageSync('config', data)
			state.config = data
		},
		setUser: (state, data) => {
			
			uni.setStorageSync('user', data)
			state.user = data
		},
	},
	actions: {
		setUser({ commit }, d) {
			commit('setUser', d)
		},
		setConfig({ commit }, d) {
			commit('setConfig', d)
		},
	}
})
export default {
	namespaced: false,
	...store
}